from selenium.webdriver.common.by import By


class SecurityManagementLocator:

    # 等待转圈 [class="antd4-spin-dot antd4-spin-dot-spin"]
    wait = (By.CSS_SELECTOR,'[class="antd4-spin-dot antd4-spin-dot-spin"]')

    # Security_Management菜单
    security_management_tab = (By.XPATH, "//div[contains(@data-menu-id,'SECURITY_MANAGEMENT_CST')]/span")

    product_security_rule_tab = (By.CSS_SELECTOR, '[path="/console/securityManagement/productSecurityRule"]')

    security_audit_tab = (By.CSS_SELECTOR, '[path="/console/securityManagement/securityAudit"]')

    """
      查询条件
    """
    # [title="81-100"]  //span[text()="Please select"]
    click_select_security_score = (By.CSS_SELECTOR,'[class="antd4-select-selection-overflow"]')
    # 动态获取security_score区间选项
    def get_security_score(self, str):
        str_old = '//div[@class="rc-virtual-list-holder-inner"]//div[@title="'
        str_new = str_old + str + '"]'
        return (By.XPATH, str_new)

    # account_email查询条件
    search_account_email = (By.CSS_SELECTOR,'[id="account"]')
    # 点击查询
    click_saerch = (By.CSS_SELECTOR,'[aria-label="search"]')


    # 查询列表第一条数据email
    first_account_email = (By.XPATH,'(//tr[@class="antd4-table-row antd4-table-row-level-0"])[1]/td[1]/div/span')
    # 查询列表第一条数据Phone Number
    first_phone_number = (By.XPATH,'(//tr[@class="antd4-table-row antd4-table-row-level-0"])[1]/td[5]/div')
    # 第一条数据的 log按钮
    first_log_button = (By.XPATH,'(//button[@type="button"])[2]')

    # 翻页
    page_total = (By.CSS_SELECTOR, '[class="antd4-pagination-total-text"]')
    page_total_one = (By.CSS_SELECTOR,'[title="2"]')

    #security_audit页面列表属性
    #Account Email
    audit_list_account_email = (By.XPATH,'//th[text() = "Account Email"]')
    #Status
    audit_list_account_status = (By.XPATH,'//span[text() = "Status"]')
    #Security Score
    audit_list_account_security_score = (By.XPATH,'//span[text() = "Security Score"]')
    #User Name
    audit_list_account_user_name = (By.XPATH,'//th[text() = "User Name"]')
    #Phone Number
    audit_list_account_phone_number = (By.XPATH,'//th[text() = "Phone Number"]')
    #Organization
    audit_list_account_organization = (By.XPATH,'//th[text() = "Organization"]')
    #Online Status
    audit_list_account_online_status = (By.XPATH,'//span[text() = "Online Status"]')
    #Latest Online Time
    audit_list_account_latest_online_time = (By.XPATH,'//th[text() = "Latest Online Time (UTC+08:00)"]')
    #Actions
    audit_list_account_actions = (By.XPATH,'//th[text() = "Actions"]')

    #security score选择框
    security_score_selection = (By.XPATH, "//div[contains(@class,'antd4-select-selection-overflow')]")

    #account_email/phone_number查询输入框
    account_email_query_input = (By.ID, "account")
    #搜索按钮
    account_email_query_button = (By.XPATH,"//button[contains(@class,'antd4-btn antd4-btn-default antd4-btn-icon-only antd4-input-search-button')]")

    #Log按钮
    Log_button = (By.XPATH, "//button[contains(@class,'antd4-btn-link')]")
    #Log页面日志列表字段
    #request_time
    audit_log_list_request_time = (By.XPATH,'//th[text() = "Request Time (UTC+08:00)"]')
    #request_ip
    audit_log_list_request_ip = (By.XPATH,'//th[text() = "Request IP"]')
    #request_form
    audit_log_list_request_form = (By.XPATH,'//span[text() = "Request Content"]')
    #request_operation
    audit_log_list_risk_operation = (By.XPATH,'//span[text() = "Risk Operation"]')
    #mapping_rule
    audit_log_list_mapping_rule = (By.XPATH,'//th[text() = "Mapping Rule"]')
    #score_reduce
    audit_log_list_score_reduce = (By.XPATH,'//th[text() = "Score Reduce"]')
    #remarks
    audit_log_list_remarks = (By.XPATH,'//th[text() = "Remarks"]')

    #Product security role页面
    #import按钮
    product_security_rule_import_button = (By.XPATH,"//button[contains(@class,'antd4-btn-primary')]")

    #securiy_inspect_on按钮
    security_inspect_on_button = (By.XPATH,"//button[contains(@class,'antd4-switch')]")

    #点击security_inspect_on后，弹窗acknowledge确认按钮
    security_inspect_on_acknowledge_button = (By.XPATH,"/html/body/div[9]/div/div[2]/div/div[2]/div[2]/label/span[1]/input")


    ###########  APIGW APP Audit

    # APIGW APP Audit tab页
    apigw_app_audit_tab = (By.CSS_SELECTOR, '[path="/console/appAudit"]')

    # 动态获取APIGW APP Audit tab页列表数据项
    def get_apigw_app_audit_list1(self, str):
        str_old = '//th[text()="'
        str_new = str_old + str + '"]'
        return (By.XPATH, str_new)

    def get_apigw_app_audit_list2(self, str):
        str_old = '//span[text()="'
        str_new = str_old + str + '"]'
        return (By.XPATH, str_new)

    # app name 查询输入框
    app_name = (By.CSS_SELECTOR,'[id="appName"]')
    # app binding email
    app_binding_email = (By.CSS_SELECTOR,'[id="bindEmail"]')
    # last_inquiry_user_email
    last_inquiry_user_email = (By.CSS_SELECTOR,'[id="inquiryUser"]')
    # 查询按钮
    click_app_audit_search = (By.CSS_SELECTOR,'[class="antd4-btn antd4-btn-primary"]')

    # first_app_name
    first_app_name = (By.XPATH,'(//tr[@class="antd4-table-row antd4-table-row-level-0"])[1]/td[1]/div')
    # first_app_binding_email
    first_app_binding_email = (By.XPATH,'(//tr[@class="antd4-table-row antd4-table-row-level-0"])[1]/td[7]/div')
    # first_last_inquiry_user_email
    first_last_inquiry_user_email = (By.XPATH,'(//tr[@class="antd4-table-row antd4-table-row-level-0"])[1]/td[5]/div')
    # 第一条数据的log按钮
    first_click_log = (By.XPATH,'(//tr[@class="antd4-table-row antd4-table-row-level-0"])[1]//button[@type="button"]')

    ## APIGW APP Audit Log页面
    # logu页面标题
    apigw_app_audit_log_page = (By.XPATH,'//*[@class="cre-page-container-header-panel-left"]//div[@class="antd4-space-item"][1]/div')
    # request_path
    request_path = (By.CSS_SELECTOR,'[id="requestPath"]')
    # inquiryUser
    inquiryUser = (By.CSS_SELECTOR,'[id="inquiryUser"]')
    # requestId
    requestId = (By.CSS_SELECTOR,'[id="requestId"]')
    # date
    date = (By.CSS_SELECTOR,'[id="date"]')


    ###########  Product Security Rule
    # product_security_rule 菜单
    product_security_rule_tab = (By.CSS_SELECTOR,'[path="/console/securityManagement/productSecurityRule"]')
    # Elastic Compute Service 菜单
    elastic_compute_service_menu = (By.CSS_SELECTOR,'[title="Elastic Compute Service"]')
    # Elastic Compute Service 页面标题
    check_elastic_compute_service_title = (By.XPATH,'(//div[text()="Elastic Compute Service"])[1]')
    # import按钮
    click_import = (By.XPATH,'//span[text()="Import"]/..')
    # Forbidden Data输入框
    forbidden_date_list = (By.CSS_SELECTOR,'[id="blackList"]')
    # submit按钮
    click_submit = (By.XPATH,'//span[text()="Submit"]/..')
    # delete按钮
    def click_delete(self, str):
        str_old = '//div[text()="'
        str_new = str_old + str + '"]/../../../td[6]//button[@type="button"]'
        return (By.XPATH, str_new)
    # Confirm按钮
    click_Confirm=(By.XPATH,'//span[text()="Confirm"]/ancestor::button[not(@disabled)]')
    # security_inspect_on 开启拦截按钮
    security_inspect_on = (By.XPATH,'//div[@class="antd4-switch-handle"]/..')
    # I acknowledge 勾选
    click_i_acknowledge = (By.XPATH,'//div[text()="I acknowledge"]/../../span[@class="antd4-checkbox"]')












